package com.bc.web.controller.admin;

import java.io.File;

import com.fs.common.extend.FSController;
import com.bc.web.service.ReportService;
import com.jfinal.kit.StrKit;

public class ReportController extends FSController {
	public void reportPage() {
		render("clearing/report/reportList.html");
	}

	public void download() {
		String startSettleDate = getPara("startSettleDate");
		String endSettleDate = getPara("endSettleDate");
		String reportType = getPara("reportType");
		if ("virtualBalance".equals(reportType) == false && (StrKit.isBlank(startSettleDate) || StrKit.isBlank(endSettleDate))) {
			renderFail("起止日切日期必填！");
			return;
		}
		ReportService reportService = new ReportService();
		File file = null;
		if ("localDetail".equals(reportType)) {
			file = reportService.localDetail(null, null, startSettleDate, endSettleDate);
		} else if ("channelDetail".equals(reportType)) {
			file = reportService.channelDetail(startSettleDate, startSettleDate);
		} else if ("error".equals(reportType)) {
			file = reportService.error(startSettleDate, endSettleDate);
		} else if ("paymentDetail".equals(reportType)) {
			file = reportService.paymentDetail(startSettleDate, endSettleDate);
		} else if ("risk".equals(reportType)) {
			file = reportService.risk(startSettleDate, endSettleDate);
		} else if ("paymentCollect".equals(reportType)) {
			file = reportService.paymentCollect(startSettleDate, endSettleDate);
		} else {
			file = reportService.virtualBalance();
		}
		if (file == null) {
			renderFail("没有满足条件的数据");
		} else {
			renderFile(file);
		}
	}

}
